from django.http import HttpResponse
from .device import Device
from .models import UserBlackList
from .user import User


def get_device_by_id(request):
    id = request.GET.get("id", '')
    return HttpResponse(Device.objects.filter(id=id))


def device_list(request):
    return HttpResponse(Device.objects.all())


def add_user_black(request):
    device_id = request.GET.get("device_id")
    user_id = request.GET.get('user_id')
    black = UserBlackList()
    black.device_id = device_id
    user = User()
    user.id = user_id
    black.bind_user = user
    black.save()
    return HttpResponse("SUCCESS")


def get_black_user_device(request):
    user_id = request.GET.get("user_id", '')

    black = UserBlackList.objects.filter(bind_user_id=user_id)

    return HttpResponse(black)


def get_black_user_device_by_device(request):
    device_id = request.GET.get("device_id")
    return HttpResponse(UserBlackList.objects.filter(device_id=device_id))
